const Koa = require("koa");
const app = new Koa();
const views = require("koa-views");
const json = require("koa-json");
const onerror = require("koa-onerror");
const bodyparser = require("koa-bodyparser");
const logger = require("koa-logger");
var cors = require("koa2-cors");

const log = require("./routes/log");

const PagerHelper = require("./utils/PagerHelper");

// error handler
onerror(app);

// middlewares
app.use(
    bodyparser({
        enableTypes: ["json", "form", "text"],
    })
);
app.use(cors());
app.use(json());
app.use(logger());
app.use(require("koa-static")(__dirname + "/public"));

app.use(
    views(__dirname + "/views", {
        extension: "ejs",
    })
);


// routes
app.use(log.routes(), log.allowedMethods());
// error-handling
app.on("error", (err, ctx) => {

});

module.exports = app;
